package com.study.guide.codec.MessagePack;

import java.util.List;

import org.msgpack.MessagePack;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
/**
 * 	自定义解码器
 * @author nrzt
 *
 */
public class MsgpackDecoder  extends MessageToMessageDecoder<ByteBuf>{

	@Override
	protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
		final int length = msg.readableBytes();
		final byte[] array =new byte[length];
		msg.readBytes(array);
		//msg.getBytes(msg.readerIndex(),array,0,length);
		MessagePack msgpack = new MessagePack();
		out.add(msgpack.read(array));
	}

}
